package com.css.fxfzysx.modules.vabStructure.service.impl;

import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.modules.cztDataMange.entity.RcpInformationEntity;
import com.css.fxfzysx.modules.cztDataMange.repository.BacInformationRepository;
import com.css.fxfzysx.modules.vabStructure.entity.CztConcreteDestroyCalc;
import com.css.fxfzysx.modules.vabStructure.entity.CztConcreteDestroyParams;
import com.css.fxfzysx.modules.vabStructure.param.RcpInformationParam;
import com.css.fxfzysx.modules.vabStructure.repository.RcpInformationRepository;
import com.css.fxfzysx.modules.vabStructure.service.RcpInformationService;
import com.css.fxfzysx.util.PlatformDateUtils;
import com.css.fxfzysx.util.UUIDGenerator;
import com.css.fxfzysx.web.PlatformSessionContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
@Slf4j
public class RcpInformationServiceImpl implements RcpInformationService {

    @Autowired
    private RcpInformationRepository rcpInformationRepository;

    @Autowired
    private BacInformationRepository bacInformationRepository;

    @Override
    public RestResponse countRcpInformation(RcpInformationParam rcpInformationParam) {
        try {
            List<CztConcreteDestroyParams> cztConcreteDestroyParamsList = rcpInformationParam.getCztConcreteDestroyParamsList();
            List<CztConcreteDestroyCalc> cztConcreteDestroyCalcs = rcpInformationParam.getCztConcreteDestroyCalcs();
            cztConcreteDestroyParamsList.stream().forEach(it->{
                it.setNu(new BigDecimal(1));
                it.setNl(new BigDecimal(1));
                it.setMz1(new BigDecimal(1));
                it.setMz2(new BigDecimal(1));
                it.setM5nh1(new BigDecimal(1));
                it.setM5nh2(new BigDecimal(1));
                it.setMu(new BigDecimal(1));
                it.setMl(new BigDecimal(1));
                it.setQcz1(new BigDecimal(1));
                it.setQcz2(new BigDecimal(1));
                it.setYieldPower(new BigDecimal(1));
                it.setQz(new BigDecimal(1));
                it.setQmy(new BigDecimal(1));
                it.setQwy1(new BigDecimal(1));
                it.setQwy2(new BigDecimal(1));
                it.setLcsjczl(new BigDecimal(1));
            });

            cztConcreteDestroyCalcs.stream().forEach(it->{
                it.setQmi(new BigDecimal(1));
                it.setFloorBearCapacity(new BigDecimal(1));
                it.setQi(new BigDecimal(1));
                it.setU6(new BigDecimal(1));
                it.setU7(new BigDecimal(1));
                it.setU8(new BigDecimal(1));
                it.setU9(new BigDecimal(1));
                it.setU10(new BigDecimal(1));
            });
            return RestResponse.succeed(rcpInformationParam);
        } catch (Exception e) {
            String errorMessage = "失败";
            log.error(errorMessage,e);
            return RestResponse.fail(errorMessage);
        }
    }

    @Override
    public RestResponse saveRcpInformation(RcpInformationParam rcpInformationParam) {
        try {
            String uuid = UUIDGenerator.getUUID();
            RcpInformationEntity rcpInformationEntity = rcpInformationParam.getRcpInformationEntity();
            List<CztConcreteDestroyParams> cztConcreteDestroyParamsList = rcpInformationParam.getCztConcreteDestroyParamsList();
            List<CztConcreteDestroyCalc> cztConcreteDestroyCalcs = rcpInformationParam.getCztConcreteDestroyCalcs();
            rcpInformationEntity.setCreateUser(PlatformSessionContext.getUserID());
            rcpInformationEntity.setCcpiId(uuid);
            rcpInformationEntity.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
            rcpInformationEntity.setDelFlag("0");
            bacInformationRepository.saveRcpInformation(rcpInformationEntity);
            cztConcreteDestroyParamsList.stream().forEach(it->{
                it.setProjectId(uuid);
                it.setDelFlag("0");
                it.setCcdpId(UUIDGenerator.getUUID());
                it.setCreateUser(PlatformSessionContext.getUserID());
                it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                rcpInformationRepository.saveConcreteDestroyParams(it);
            });
            cztConcreteDestroyCalcs.stream().forEach(it->{
                it.setProjectId(uuid);
                it.setDelFlag("0");
                it.setCcdcId(UUIDGenerator.getUUID());
                it.setCreateUser(PlatformSessionContext.getUserID());
                it.setCreateTime(PlatformDateUtils.getCurrentTimestamp());
                rcpInformationRepository.saveConcreteDestroyCalcs(it);
            });
            return RestResponse.succeed("成功");
        } catch (Exception e) {
            String errorMessage = "失败";
            log.error(errorMessage,e);
            return RestResponse.fail(errorMessage);
        }
    }
}
